<?php


namespace app\admin\controller;


use app\common\controller\BaseController;
use think\App;
use app\admin\model\Notification as notificationModel;

class Notification extends BaseController
{
    protected $model;

    public function __construct(App $app, notificationModel $model)
    {
        parent::__construct($app);
        $this->model = $model;
    }

    /**
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * 列表
     */
    public function query()
    {
        $where = [];
        $where['deleted'] = 0;
        $field = 'id,message';
        $page = input('page/d', 1);
        $pageSize = input('page_size/d', 10);
        $order = ['create_time' => 'asc'];
        return $this->model->getList($where, $field, $order, $page, $pageSize);
    }

    /**
     * @return array
     * 添加
     */
    public function add()
    {
        try {
            return $this->model->add($this->params);
        } catch (\Exception $ex) {
            return $this->returnException($ex);
        }
    }

    /**
     * @return array
     * 编辑
     */
    public function edit()
    {
        try {
            return $this->model->edit($this->params);
        } catch (\Exception $ex) {
            return $this->returnException($ex);
        }
    }

    /**
     * @return array
     * 删除
     */
    public function delete()
    {
        try {
            return $this->model->remove($this->params);
        } catch (\Exception $ex) {
            return $this->returnException($ex);
        }
    }
}